# encode: utf-8

import faker

fake = faker.Faker("zh_CN")


import random


def generate_id_numbers_18_to_25(count):
    id_numbers = []
    for _ in range(count):
        id_number = fake.ssn(min_age=18, max_age=25)
        id_numbers.append(id_number)
    return id_numbers


# 调用函数生成 10 个身份证号
# id_numbers = generate_id_numbers_18_to_25(10)
# print(id_numbers)


num6 = []
numyyyymmdd = []
numrand = []
numvalid = []

# with open("fakk.txt", "r", encoding="utf8") as f:
#     idcardtxt = f.readlines()
#     for i in idcardtxt:
#         # print(i)
#         # print(i.split()[0])
#         num6.append(i.split()[0])


# n666 = random.choice(num6)
# print(n666)


def getvalid(idcard):

    # 权重因子
    weights = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
    # 校验码映射
    validators = ["1", "0", "X", "9", "8", "7", "6", "5", "4", "3", "2"]

    # 计算加权和
    total = 0
    for i in range(17):
        total += int(idcard[i]) * weights[i]

    # 计算校验码
    mod = total % 11
    expected_validator = validators[mod]
    return expected_validator


def genIdcard():

    idcard = "".join(
        [
            random.choice(num6),
            fake.ssn(min_age=18, max_age=25)[6:14],
            str(random.randint(0, 777)).zfill(3),
        ]
    )

    idcard = "".join([idcard, getvalid(idcard)])

    return idcard


# idarr = idcardtxt.splitlines()
# print(idarr)


def genData():
    one = [
        fake.name(),
        fake.phone_number(),
        # fake.password(),
        fake.address(),
        # fake.ssn(),
        genIdcard(),
    ]
    # print("|".join(one))
    return one


# for i in range(100):
#     (name, phone, address, idcard) = genData()
#     print(
#         f"""INSERT INTO `dss_student` ( `name`, `snote`,  `idcard`, `address`, `phone`) VALUES
# ('{name}',	NULL,	'{idcard}',	'{address}',	'{phone}');"""
#     )



import datetime


data = []
for _ in range(100):
    name = fake.name()
    # 生成1990-2010年间的日期
    birth_date = fake.date_between_dates(
        date_start=datetime.datetime(1990,1,1), 
        date_end=datetime.datetime(2010,12,31)
    ).strftime("%Y-%m-%d")
    data.append((name, birth_date, fake.ssn(min_age=18, max_age=25)))

print(data)

